var Class = {
    create: function(){
        return function(){
            this.initialize.apply(this, arguments);
        }
    }
};

var	scormAPI = Class.create();

scormAPI.prototype = {
	mStringFalse : "false",
	mStringTrue : "true",
	mInitializedState : false,
	mTerminatedState : false,
	mTerminateCalled : false,
	LastErrorCode : "0",
	initialize : function()	{
		
	},
	isInitialized : function() {
		if (!this.mInitializedState) {
			if (DataModel.debug) 
				alert("DMErrorCodes.GEN_GET_FAILURE");
			DataModel.error.setCurrentError("301");
		}
		return this.mInitializedState;
	},
	Initialize : function(param) {
		DataModel.error.setCurrentError("0");
		if (DataModel.debug) {
			alert("*********************\nIn API::Initialize\n*********************");
			alert("param : " + param);
		}
		var result = this.mStringFalse;
		if (this.mTerminatedState) {
			DataModel.error.setCurrentError("104");
			return result;
		}
		this.mTerminatedState = false;
		this.mTerminateCalled = false;
		
		if ( typeof(param) == 'undefined' || param != "") {
			DataModel.error.setCurrentError("201");
		} else if (this.mInitializedState ) {
			DataModel.error.setCurrentError("103");
		} else {
			this.mInitializedState = true;
			
			// 서버측 모듈 개발하면서 변경해야 함....
			// DWR 호출방식은 변경하지 않을 예정임
			// 변경 범위는 데이터모델을 통해 데이터베이스로 입력되는 상황에 대해서 변경 작업을 진행할 예정임
			var result = dwrUtil.invokeMap( scormAPI.map.toMap(), { beanId: "usr.scormDmDWR", method: "Initialize"});
			this.dm = result;
			
			DataModel.error.setCurrentError("0");
			result = this.mStringTrue;
		}
		
		if (DataModel.debug) {
			alert("*******************************\n"
			+"Done Processing Initialize()\n"+result
			+"*******************************");
		}
		
		return result;
	},
	GetValue : function(object) {
		var result = "";
		
		DataModel.error.setCurrentError("0");
		if (DataModel.debug) {
			alert("*******************\n"
			+"In API::GetValue\n"
			+"*******************\n"
			+"GetValue Parameter:"+element);
		}
		
		if (this.mTerminatedState ) {
			if (DataModel.debug)
				alert("APIErrorCodes.GET_AFTER_TERMINATE");
			DataModel.error.setCurrentError("123");
			return result;
		}

		if ( typeof(object) == 'undefined' || object == "") {
			if (DataModel.debug)
				alert("DMErrorCodes.GEN_GET_FAILURE");
			DataModel.error.setCurrentError("301");
			return result;
		}
		if (!this.isInitialized()) {
			if (DataModel.debug)
				alert("APIErrorCodes.GET_BEFORE_INIT");
			DataModel.error.setCurrentError("122");
			return result;
		}
		
		if (DataModel.debug)
			alert("Request being processed: GetValue(" + element + ")");
		result = DataModel.validation.check(object, "get");	
		
		if (DataModel.debug) {
			alert("************************************\n"
			+"Processing done for API::LMSGetValue\n"
			+"************************************");
		}
		return result;
	},
	SetValue : function(object, value) {
		var result = mStringFalse;
		DataModel.error.setCurrentError("0");
		// Assume failure
		var result = false;
		if (DataModel.debug) {
			alert("*****************\n"
			+"In API::SetValue() \n"
			+"****************");
		}
		
		if (this.mTerminatedState) {
			if (DataModel.debug)
				alert("APIErrorCodes.SET_AFTER_TERMINATE");
			DataModel.error.setCurrentError("133");
			return result;
		}
		
		if ( typeof(object) == 'undefined' || object == "") {
			if (DataModel.debug)
				alert("DMErrorCodes.GEN_GET_FAILURE");
			DataModel.error.setCurrentError("351");
			return result;
		}
		
		if (!this.isInitialized()) {
			if (DataModel.debug)
				alert("APIErrorCodes.SET_BEFORE_INIT");
			DataModel.error.setCurrentError("132");
			return result;
		}
		
		if (DataModel.debug) {
			alert("Request being processed: SetValue(" 
				+ element + "," + value + ")\n"
				+"Looking for the element " + value );
		}
		
		result = DataModel.validation.check(object, "set", value);	
		
		if (DataModel.debug) {
			alert("************************************\n"
				+"Processing done for API::SetValue\n"
				+"************************************");
		}
		
		return result;
	},
	Terminate : function(param) {
		var result = this.mStringFalse;
		if (DataModel.debug) {
			alert("*****************");
			alert("In API::Terminate");
			alert("*****************");
			alert("");
		}

		this.mTerminateCalled = true;

		if (this.mTerminatedState) {
			if (DataModel.debug) 
				alert("APIErrorCodes.TERMINATE_AFTER_TERMINATE");
			DataModel.error.setCurrentError("113");
			return result;
		}

		if (this.isInitialized() == false) {
			if (DataModel.debug) 
				alert("APIErrorCodes.TERMINATE_BEFORE_INIT");
			DataModel.error.setCurrentError("112");
			return result;
		}
		
		if ( typeof(param) == 'undefined' || param != "")
		{
			if (DataModel.debug)
				alert("DMErrorCodes.TERMINATE_GEN_ARGUMENT_ERROR");
			DataModel.error.setCurrentError("201");
		}
		
		
	},
	
	Commit : function() {
		
	},
	
	GetLastError : function() {
		return DataModel.error.getCurrentCode;
	},
	GetErrorString : function(errorCode) {
		return DataModel.error.getCurrentErrorString;
	},
	GetDiagnostic : function(errorCode) {
		return DataModel.error.getDiagnostic;
	}
}






